﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nature.Data
{
    public interface ISpeciesDataFallBack<T> 
    {
        bool CanConstruct(string speciesID, ReadOnlyCollection<object> entities);

        T Construct(string speciesID, ReadOnlyCollection<object> entities);
    }


    public class SpeciesDataFallBackQueue<T> : Queue<ISpeciesDataFallBack<T>>
    {
        public T Construct(string speciesID, ReadOnlyCollection<object> entities)
        {
            var selected = this.FirstOrDefault(i=> i.CanConstruct(speciesID, entities));
            if( selected == null)
            { 
                throw new Exception(
                    string.Format("Could not find an appropriate fallback mechanism to construct the {0} object for the '{1}' chemical species"
                    , typeof(T).FullName, speciesID));
            }
            var data = selected.Construct(speciesID, entities);
            return data;
        }
    }


    public class AssignNitrogenGasKinParametersDataFallBack : ISpeciesDataFallBack<GasKinParameters>
    {
        public bool CanConstruct(string speciesID, ReadOnlyCollection<object> entities)
        {
            return true;
        }

        public GasKinParameters Construct(string speciesID, ReadOnlyCollection<object> entities)
        {
            // N2                 1    97.530     3.621     0.000     1.760     4.000
            return new GasKinParameters 
            {
                SpeciesID = speciesID,
                GeometryIndex = 1,
                Epsilon = 97.530,
                Sigma = 3.621,
                Mu = 0.0,
                Alpha = 1.760,
                Zrot = 4.000
            };
        }
    }

}
